local cargoboom = false

resource.AddFile("models/shelby/fixed_gibs/shelby_bonnet_gib.mdl")
resource.AddFile("models/shelby/fixed_gibs/shelby_bonnet_gib.phy")
resource.AddFile("models/shelby/fixed_gibs/shelby_bonnet_gib.dx80.vtx")
resource.AddFile("models/shelby/fixed_gibs/shelby_bonnet_gib.dx90.vtx")
resource.AddFile("models/shelby/fixed_gibs/shelby_bonnet_gib.sw.vtx")
resource.AddFile("models/shelby/fixed_gibs/shelby_bonnet_gib.vvd")

resource.AddFile("models/shelby/fixed_gibs/shelby_boot_gib.mdl")
resource.AddFile("models/shelby/fixed_gibs/shelby_boot_gib.phy")
resource.AddFile("models/shelby/fixed_gibs/shelby_boot_gib.dx80.vtx")
resource.AddFile("models/shelby/fixed_gibs/shelby_boot_gib.dx90.vtx")
resource.AddFile("models/shelby/fixed_gibs/shelby_boot_gib.sw.vtx")
resource.AddFile("models/shelby/fixed_gibs/shelby_boot_gib.vvd")

resource.AddFile("models/shelby/fixed_gibs/shelby_boot_gib.mdl")
resource.AddFile("models/shelby/fixed_gibs/shelby_boot_gib.phy")
resource.AddFile("models/shelby/fixed_gibs/shelby_boot_gib.dx80.vtx")
resource.AddFile("models/shelby/fixed_gibs/shelby_boot_gib.dx90.vtx")
resource.AddFile("models/shelby/fixed_gibs/shelby_boot_gib.sw.vtx")
resource.AddFile("models/shelby/fixed_gibs/shelby_boot_gib.vvd")

resource.AddFile("models/shelby/fixed_gibs/shelby_ldoor_gib.mdl")
resource.AddFile("models/shelby/fixed_gibs/shelby_ldoor_gib.phy")
resource.AddFile("models/shelby/fixed_gibs/shelby_ldoor_gib.dx80.vtx")
resource.AddFile("models/shelby/fixed_gibs/shelby_ldoor_gib.dx90.vtx")
resource.AddFile("models/shelby/fixed_gibs/shelby_ldoor_gib.sw.vtx")
resource.AddFile("models/shelby/fixed_gibs/shelby_ldoor_gib.vvd")

resource.AddFile("models/shelby/fixed_gibs/shelby_rdoor_gib.mdl")
resource.AddFile("models/shelby/fixed_gibs/shelby_rdoor_gib.phy")
resource.AddFile("models/shelby/fixed_gibs/shelby_rdoor_gib.dx80.vtx")
resource.AddFile("models/shelby/fixed_gibs/shelby_rdoor_gib.dx90.vtx")
resource.AddFile("models/shelby/fixed_gibs/shelby_rdoor_gib.sw.vtx")
resource.AddFile("models/shelby/fixed_gibs/shelby_rdoor_gib.vvd")

resource.AddFile("models/mini/fixed_gibs/mini_bonnet_gib.mdl")
resource.AddFile("models/mini/fixed_gibs/mini_bonnet_gib.phy")
resource.AddFile("models/mini/fixed_gibs/mini_bonnet_gib.dx80.vtx")
resource.AddFile("models/mini/fixed_gibs/mini_bonnet_gib.dx90.vtx")
resource.AddFile("models/mini/fixed_gibs/mini_bonnet_gib.sw.vtx")
resource.AddFile("models/mini/fixed_gibs/mini_bonnet_gib.vvd")

resource.AddFile("models/mini/fixed_gibs/mini_boot_gib.mdl")
resource.AddFile("models/mini/fixed_gibs/mini_boot_gib.phy")
resource.AddFile("models/mini/fixed_gibs/mini_boot_gib.dx80.vtx")
resource.AddFile("models/mini/fixed_gibs/mini_boot_gib.dx90.vtx")
resource.AddFile("models/mini/fixed_gibs/mini_boot_gib.sw.vtx")
resource.AddFile("models/mini/fixed_gibs/mini_boot_gib.vvd")

local function VehicleSpawn(ply, car)

	print("Spawned Car")

	if !car.VehicleTable.breakable then return end

	car:SetHealth(100)

	car:Fire("SetBodyGroup", "0", 0)

	if car:GetModel() == "models/lambo/lambo.mdl" then

		local bonnet=ents.Create("fueled_gib")
		bonnet:SetModel("models/lambo/lambo_bonnet_gib.mdl")
		bonnet:SetPos(car:GetPos())
		bonnet:SetAngles(car:GetAngles())
		bonnet:Spawn()
		bonnet:SetSkin(car:GetSkin())
		bonnet:SetCar(car)

		local boot=ents.Create("fueled_gib")
		boot:SetModel("models/lambo/lambo_boot_gib.mdl")
		boot:SetPos(car:GetPos())
		boot:SetAngles(car:GetAngles())
		boot:Spawn()
		boot:SetSkin(car:GetSkin())
		boot:SetCar(car)

		local ldoor=ents.Create("fueled_gib")
		ldoor:SetModel("models/lambo/lambo_ldoor_gib.mdl")
		ldoor:SetPos(car:GetPos())
		ldoor:SetAngles(car:GetAngles())
		ldoor:Spawn()
		ldoor:SetSkin(car:GetSkin())
		ldoor:SetCar(car)

		local rdoor=ents.Create("fueled_gib")
		rdoor:SetModel("models/lambo/lambo_rdoor_gib.mdl")
		rdoor:SetPos(car:GetPos())
		rdoor:SetAngles(car:GetAngles())
		rdoor:Spawn()
		rdoor:SetSkin(car:GetSkin())
		rdoor:SetCar(car)

		car.dmgcontroller=ents.Create("fueled_damage_control")
		car.dmgcontroller:SetPos(car:GetPos())
		car.dmgcontroller:SetAngles(car:GetAngles())
		car.dmgcontroller:SetCar(car)
		car.dmgcontroller:Spawn()
		car.dmgcontroller:SetParent(car)

		constraint.Weld(bonnet,car,0,0,0,true)
		constraint.Weld(boot,car,0,0,0,true)
		constraint.Weld(ldoor,car,0,0,0,true)
		constraint.Weld(rdoor,car,0,0,0,true)

		print("Entities Spawned...")
	end

	if car:GetModel() == "models/caterham/caterham.mdl" then

		car:SetHealth(100)

		local bonnet=ents.Create("fueled_gib")
		bonnet:SetModel("models/caterham/caterham_bonnet_gib.mdl")
		bonnet:SetPos(car:GetPos())
		bonnet:SetAngles(car:GetAngles())
		bonnet:Spawn()
		bonnet:SetSkin(car:GetSkin())
		bonnet:SetCar(car)

		local boot=ents.Create("fueled_gib")
		boot:SetModel("models/caterham/caterham_boot_gib.mdl")
		boot:SetPos(car:GetPos())
		boot:SetAngles(car:GetAngles())
		boot:Spawn()
		boot:SetSkin(car:GetSkin())
		boot:SetCar(car)

		car.dmgcontroller=ents.Create("fueled_damage_control")
		car.dmgcontroller:SetPos(car:GetPos())
		car.dmgcontroller:SetAngles(car:GetAngles())
		car.dmgcontroller:SetCar(car)
		car.dmgcontroller:Spawn()
		car.dmgcontroller:SetParent(car)

		constraint.Weld(bonnet,car,0,0,0,true)
		constraint.Weld(boot,car,0,0,0,true)

		print("Entities Spawned...")
	end

	if car:GetModel() == "models/shelby/shelby.mdl" then

		local bonnet=ents.Create("fueled_gib")
		bonnet:SetModel("models/shelby/fixed_gibs/shelby_bonnet_gib.mdl")
		bonnet:SetPos(car:GetPos())
		bonnet:SetAngles(car:GetAngles())
		bonnet:Spawn()
		bonnet:SetSkin(car:GetSkin())
		bonnet:SetCar(car)

		local boot=ents.Create("fueled_gib")
		boot:SetModel("models/shelby/fixed_gibs/shelby_boot_gib.mdl")
		boot:SetPos(car:GetPos())
		boot:SetAngles(car:GetAngles())
		boot:Spawn()
		boot:SetSkin(car:GetSkin())
		boot:SetCar(car)

		local ldoor=ents.Create("fueled_gib")
		ldoor:SetModel("models/shelby/fixed_gibs/shelby_ldoor_gib.mdl")
		ldoor:SetPos(car:GetPos())
		ldoor:SetAngles(car:GetAngles())
		ldoor:Spawn()
		ldoor:SetSkin(car:GetSkin())
		ldoor:SetCar(car)

		local rdoor=ents.Create("fueled_gib")
		rdoor:SetModel("models/shelby/fixed_gibs/shelby_rdoor_gib.mdl")
		rdoor:SetPos(car:GetPos())
		rdoor:SetAngles(car:GetAngles())
		rdoor:Spawn()
		rdoor:SetSkin(car:GetSkin())
		rdoor:SetCar(car)

		car.dmgcontroller=ents.Create("fueled_damage_control")
		car.dmgcontroller:SetPos(car:GetPos())
		car.dmgcontroller:SetAngles(car:GetAngles())
		car.dmgcontroller:SetCar(car)
		car.dmgcontroller:Spawn()
		car.dmgcontroller:SetParent(car)

		constraint.Weld(bonnet,car,0,0,0,true)
		constraint.Weld(boot,car,0,0,0,true)
		constraint.Weld(ldoor,car,0,0,0,true)
		constraint.Weld(rdoor,car,0,0,0,true)

		print("Entities Spawned...")
	end

	if car:GetModel() == "models/mini/mini.mdl" then

		local bonnet=ents.Create("fueled_gib")
		bonnet:SetModel("models/mini/fixed_gibs/mini_bonnet_gib.mdl")
		bonnet:SetPos(car:GetPos())
		bonnet:SetAngles(car:GetAngles())
		bonnet:Spawn()
		bonnet:SetSkin(car:GetSkin())
		bonnet:SetCar(car)

		local boot=ents.Create("fueled_gib")
		boot:SetModel("models/mini/fixed_gibs/mini_boot_gib.mdl")
		boot:SetPos(car:GetPos())
		boot:SetAngles(car:GetAngles())
		boot:Spawn()
		boot:SetSkin(car:GetSkin())
		boot:SetCar(car)

		local ldoor=ents.Create("fueled_gib")
		ldoor:SetModel("models/mini/mini_ldoor_gib.mdl")
		ldoor:SetPos(car:GetPos())
		ldoor:SetAngles(car:GetAngles())
		ldoor:Spawn()
		ldoor:SetSkin(car:GetSkin())
		ldoor:SetCar(car)

		local rdoor=ents.Create("fueled_gib")
		rdoor:SetModel("models/mini/mini_rdoor_gib.mdl")
		rdoor:SetPos(car:GetPos())
		rdoor:SetAngles(car:GetAngles())
		rdoor:Spawn()
		rdoor:SetSkin(car:GetSkin())
		rdoor:SetCar(car)

		car.dmgcontroller=ents.Create("fueled_damage_control")
		car.dmgcontroller:SetPos(car:GetPos())
		car.dmgcontroller:SetAngles(car:GetAngles())
		car.dmgcontroller:SetCar(car)
		car.dmgcontroller:Spawn()
		car.dmgcontroller:SetParent(car)

		constraint.Weld(bonnet,car,0,0,0,true)
		constraint.Weld(boot,car,0,0,0,true)
		constraint.Weld(ldoor,car,0,0,0,true)
		constraint.Weld(rdoor,car,0,0,0,true)

		print("Entities Spawned...")
	end
end
hook.Add( "PlayerSpawnedVehicle", "VehicleSpawn", VehicleSpawn )

local function EntDamaged(ent,inflictor,attacker,amount,dmginfo)

	if !ent:IsValid() then return end

	--[[if ent:GetModel() != "models/lambo/lambo.mdl" then return end
	if ent:GetModel() != "models/caterham/caterham.mdl" then return end
	if ent:GetModel() != "models/shelby/shelby.mdl" then return end
	if ent:GetModel() != "models/mini/mini.mdl" then return end]]

	if ent.dmgcontroller and ent.dmgcontroller:IsValid() then
		ent.dmgcontroller:TakeHealth(math.Round(dmginfo:GetDamage()*10000)/2)
	end
end

hook.Add( "EntityTakeDamage", "EntDamaged", EntDamaged )